package com.tfjybj.msg.commons.utils;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

/**
 * @Description: 统一返回结果
 * @Author: xuziguo
 * @Date: 2021/4/17 上午 11:26
 * @Modified By:
 * @Modify Date:
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MsgResult implements Serializable {

    private static final long serialVersionUID = -1617443048863070570L;

    //结果状态码
    private String code;

    //响应结果描述
    private String message;

    //返回数据
    private Object data;

    /**
     * @description: 状态码，响应结果描述
     * @author: xuziguo
     * @date: 2021/4/17 上午 11:31
     * @param: [code, message]
     * @return:
     */
    private MsgResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @description: 状态码，响应结果描述，数据
     * @author: xuziguo
     * @date: 2021/4/17 上午 11:31
     * @param: [code, message, data]
     * @return:
     */
    private MsgResult(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static MsgResult build(String code, String msg) {
        return new MsgResult(code, msg);
    }

    public static MsgResult build(String code, String msg, Object data) {
        return new MsgResult(code, msg, data);
    }

    //get方法必须要有，否则swagger里得不到这些属性
    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

}
